package com.yidu.BusinessData.mapper;

import com.yidu.BusinessData.entity.securityAccrued;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author 周楠櫻木
 * @version 1.0
 * @date 2022/12/13
 */
@Mapper
public interface SecurityAccruedMapper {
    @Select("SELECT f.*,s.`securityName` FROM securityAccrued f LEFT JOIN SECURITY s ON s.`securityId`=f.`securityId` LEFT JOIN cash c ON f.`cashId`=c.`cashId` where 1=1 ${term}  limit #{page},#{row}")
    List<securityAccrued> selectSecurityAccrued(Map map);
    /**
     * 查询总条数
     * @param map
     * @return
     */
    @Select("select count(*) from securityAccrued where 1=1 ${term}")
    int selectSecurityAccruedCont(Map map);

    /**
     * 新增数据
     * @param securityAccrued
     * @return
     */
    @Insert("INSERT INTO securityAccrued VALUES(#{securityAccruedId},#{businessTime},fundId=${1},#{cashId},#{securityId},#{businessType},#{fundFlow},#{money},#{Remark})")
    int addSecurityAccrued(securityAccrued securityAccrued);

    /**
     * 删除数据
     * @param securityAccruedId
     */
    @Delete("delete from securityAccrued where securityAccruedId=#{securityAccruedId}")
    void deleteSecurityAccrued(String securityAccruedId);

    /**
     * 修改现金的应收应付
     * @param securityAccrued
     * @return
     */
    @Update("update securityAccrued set businessTime=#{businessTime},fundId=#{fundId},cashId=#{cashId},securityId=#{securityId},businessType=#{businessType},fundFlow=#{fundFlow},money=#{money},Remark=#{Remark} where securityAccruedId=#{securityAccruedId}")
    int updateSecurityAccrued(securityAccrued securityAccrued);


    @Select("select max(securityAccruedId) from securityAccrued")
    String maxSecurityAccruedId();

    @Delete("DELETE FROM securityAccrued WHERE businessTime= #{businessTime} AND cashId=#{cashId}")
    int deleteSecurityAccrueds(securityAccrued securityAccrued);

    @Select("select count(*) from securityAccrued where securityAccruedId=#{securityAccruedId}")
    int selectCashAccrueds(String securityAccruedId);



    /**
     * 查询指定日期的证券清算款
     *
     * @param time 查询日期
     * @return double 清算款合计
     * @author 任俊杰
     */
    @Select("select sum(money) from from securityAccrualStock where date = #{time} and securityType= 1 ")///////////
    Double getLiquidationMoney(String time);

}
